package cn.wolfcode.trip.api.controller;

import cn.wolfcode.trip.base.domain.Dynamic;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IDynamicService;
import cn.wolfcode.trip.base.util.JsonResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("dynamics")
public class DynamicController {

    @Autowired
    private IDynamicService dynamicService;

    @PostMapping
    @ResponseBody
    public void save(Dynamic dynamic) {
        dynamicService.insert(dynamic);
    }

    @GetMapping
    @ResponseBody
    public PageInfo query(QueryObject qo){
        qo.setOrderBy("createTime desc");
        qo.setPageSize(4);
        PageInfo dynamicsPageInfo = dynamicService.query(qo);
        return dynamicsPageInfo;
    }

}
